<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Crypt;
use Session;

class DengluController extends Controller
{	
	// 登陆页面
    public function denglu()
    {
    	return view('admin.denglu.denglu');
    }

    // 登陆验证页面
    public function dodenglu(Request $request)
    {
    	$data = $request -> except('_token');
    	$username = $data['username'];
    	$password = $data['password'];

    	$res = DB::table('user') -> where('username',$username) -> first();

    	// 判断
    	if(!$res)
    	{
    		return back() -> with(['error' => '用户名或密码错误']);
    	}

    	//解密  密码
        $pwd = Crypt::decrypt($res -> password);
        

    	//判断
    	if($pwd != $password)
    	{
    		return back() -> with(['error' => '用户名或密码错误']);
    	}else if($res -> quanxian != 2)
    	{
    		return back() -> with(['error' => '您不是管理员']);
    	}else if($res -> status != 1)
    	{
    		return back() -> with(['error' => '您的账号已被禁止']);
    	}else
    	{
    		Session::flash('id',$res -> id);
        	Session::flash('username',$res -> username);
    		return redirect('admin/index/index');
    	}
    }
}
